<?php

/*


Author: Hoang Trum
Website: ngheweb.vn
Contact: hthoang@ngheweb.vn


*/



	class paging
	{
		private $arr = array();
		private $sotin;
		private $url;
		
		public function setUrl($value)
		{
			$this->url = $value	;
		}
		
		public function getArr()
		{
			return $this->arr;
		}
		
		public function setArr($value)
		{
			$this->arr = $value;	
		}
		
		public function getSoTin()
		{
			return $this->sotin;
		}
		
		public function setSoTin($value)
		{
			$this->sotin = $value;	
		}
		public function getPageNum()
		{
			if(isset($_GET["p"]))
			{
				return $_GET["p"];
			}
			else
				return 1;
		}
		
		function getPhanTrang()
		{
			$total = count($this->arr);
			$strTrang = array();
			$sotrang = $total/$this->sotin;
			if($sotrang > 1)
			{
				for($i=0;$i<$sotrang;$i++)
				{
					if(isset($_GET["p"])) 
						($_GET["p"] == $i+1) ? $p = "<b style='color:red;'>".($i+1)."</b>" : $p = ($i+1);
					else
						($i+1 == 1) ?  $p = "<b style='color:red;'>".($i+1)."</b>" : $p = ($i+1);	
					$strTrang[] = "<a href='".$this->url."&p=".($i+1)."'>".$p."</a>";
				}
				return "Trang ".implode(" ",$strTrang);
			}
			else
			{
				return NULL;
			}
		}
		function GetTinByPageNum()
		{
			$pagenum = $this->getPageNum();
			$nhay = ($pagenum - 1)*$this->sotin;
			$j = $nhay;			
			for($i = 0; $i<count($this->arr); $i++)
			{
				if($i >= $nhay && ($i < $nhay+$this->sotin))
					$result[] = $this->arr[$i];
			}
			return $result;
		}
	}

?>